package com.bt.lms.ui.page.teaching.supervise;

import com.bt.lms.ui.action.teaching.supervise.LookStuBtnAction;
import com.bt.lms.ui.action.teaching.supervise.PageTeachingSuperviseLookCourseResourceBtnAction;
import com.bt.lms.ui.page.sys.utils.MyHBox;
import com.bt.lms.ui.page.sys.utils.MyVBox;
import com.bt.lms.ui.page.teaching.supervise.action.RealTimeClassBtn;
import com.bt.lms.ui.page.teaching.supervise.action.TeachingCheckBtn;
import com.bt.lms.ui.page.teaching.supervise.action.GradeBtn;
import com.bt.lms.ui.page.sys.vo.StudentGradeInfo;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import java.util.ArrayList;
import java.util.List;

/**
 * 成绩及结业管理列表界面
 */
public class PageGradeList extends VBox {

    /**
     * 构造界面
     */
    public PageGradeList() {

        //自己可能用的东西
        this.setId("PageGradeList");

        //大小
        int wight = 1280;
        this.setPrefWidth(wight);
        this.setPrefHeight(650);

        //布局
        Insets insets = new Insets(0);
        this.setPadding(insets);

        //定位区域
        MyHBox locationHBox = new MyHBox();
        locationHBoxInit(locationHBox);
        this.getChildren().add(locationHBox);

        //按钮区域
        MyHBox btnHBox = new MyHBox();
        initButtonHBox(btnHBox);
        this.getChildren().add(btnHBox);

        //组件    查询条件区域
        MyVBox inquireConditionVBox = new MyVBox();
        inquireConditionVBoxInit(inquireConditionVBox);
        this.getChildren().add(inquireConditionVBox);

        //组件    列表区域
        MyVBox listVBox = new MyVBox();
        listVBoxInit(listVBox);
        this.getChildren().add(listVBox);

        //组件    搜索区域
        MyHBox searchHBox = new MyHBox();
        searchHBoxInit(searchHBox);
        this.getChildren().add(searchHBox);
    }

    /**
     * 查询区域初始化
     *
     * @param inquireConditionVBox 查询区域
     */
    private void inquireConditionVBoxInit(MyVBox inquireConditionVBox) {

        //布局
        Insets insets = new Insets(10);
        inquireConditionVBox.setPadding(insets);
        inquireConditionVBox.setSpacing(5);

        //组件（统计
        MyHBox statisticsHBox = statisticsHBoxInit();
        inquireConditionVBox.getChildren().add(statisticsHBox);

        //组件查询条件
        MyHBox queryConditionHBox = queryConditionHBoxInit();
        inquireConditionVBox.getChildren().add(queryConditionHBox);

    }

    /**
     * 查询区域的条件区域初始化
     *
     * @return 查询条件盒子
     */
    private MyHBox queryConditionHBoxInit() {

        MyHBox myHBox = new MyHBox();

        //布局
        myHBox.setSpacing(8);
        myHBox.setAlignment(Pos.CENTER_LEFT);

        //组件
        ChoiceBox<String> cb = new ChoiceBox<>();
        cb.getItems().add("结业状态");
        cb.getItems().add("未设置");
        cb.getItems().add("通过");
        cb.getItems().add("不通过");
        cb.getSelectionModel().selectFirst();
        myHBox.getChildren().add(cb);

        Label nameLab = new Label("学员姓名");
        myHBox.getChildren().add(nameLab);

        TextField nameTF = new TextField("学员姓名:");
        myHBox.getChildren().add(nameTF);

        Label sumGradeLab = new Label("总成绩:");
        myHBox.getChildren().add(sumGradeLab);

        TextField beginSumGradeTF = new TextField();
        myHBox.getChildren().add(beginSumGradeTF);

        Label label = new Label("-");
        myHBox.getChildren().add(label);

        TextField finisSumGradeTF = new TextField();
        myHBox.getChildren().add(finisSumGradeTF);


        return myHBox;
    }

    /**
     * 查询区域的统计信息初始化
     *
     * @return 统计信息盒子
     */
    private MyHBox statisticsHBoxInit() {

        MyHBox myHBox = new MyHBox();

        //布局
        myHBox.setSpacing(10);

        Label label = new Label("学员人数：500");
        myHBox.getChildren().add(label);

        Label label1 = new Label("通过人数：300");
        myHBox.getChildren().add(label1);

        Label label2 = new Label("其中免修人数：56");
        myHBox.getChildren().add(label2);

        Label label3 = new Label("未通过人数：100");
        myHBox.getChildren().add(label3);


        return myHBox;
    }


    /**
     * 搜索区域初始化
     *
     * @param searchHBox 搜索区域
     */
    private void searchHBoxInit(HBox searchHBox) {

        //数据控制
        int width = 45;
        int sumStrip = 100;//总条数
        int present = 10;//当前页数
        String sumStripStr = "总记录数" + sumStrip + "条";
        String presentStr = "/" + present;

        //布局
        Insets insets = new Insets(10);
        searchHBox.setPadding(insets);
        searchHBox.setSpacing(10);
        searchHBox.setAlignment(Pos.CENTER_RIGHT);

        //组件
        Label firstLab = new Label("« 首页");
        searchHBox.getChildren().add(firstLab);
        Label lastLab = new Label("« 上一页");
        searchHBox.getChildren().add(lastLab);
        Button pageOne = new Button("1");
        searchHBox.getChildren().add(pageOne);
        Button pageTwo = new Button("2");
        searchHBox.getChildren().add(pageTwo);
        Button pageThree = new Button("3");
        searchHBox.getChildren().add(pageThree);
        Label nextLab = new Label("下一页 »");
        searchHBox.getChildren().add(nextLab);
        Label finallyLab = new Label("尾页 »");
        searchHBox.getChildren().add(finallyLab);
        Label sumNumberLab = new Label(sumStripStr);
        searchHBox.getChildren().add(sumNumberLab);
        TextField pageNumberTF = new TextField();
        pageNumberTF.setPrefWidth(width);
        searchHBox.getChildren().add(pageNumberTF);
        Label presentLab = new Label(presentStr);
        searchHBox.getChildren().add(presentLab);
        Button notarizeBtn = new Button("GO");
        searchHBox.getChildren().add(notarizeBtn);

    }

    /**
     * 列表区域初始化
     *
     * @param listVBox 列表区域
     */
    private void listVBoxInit(MyVBox listVBox) {

        //操作区域
        operateBtnInit(listVBox);

        //列表
        //1.建立列表视图
        TableView<StudentGradeInfo> tableView = new TableView<>();

        //2.列头
        //2.1 新建列头
        TableColumn<StudentGradeInfo, HBox> selectTC = new TableColumn<>();
        TableColumn<StudentGradeInfo, String> nameTC = new TableColumn<>("学员姓名");
        TableColumn<StudentGradeInfo, String> numberTC = new TableColumn<>("学员编号");
        TableColumn<StudentGradeInfo, String> genderTC = new TableColumn<>("性别");
        TableColumn<StudentGradeInfo, String> dayGradeTC = new TableColumn<>("平时成绩");
        TableColumn<StudentGradeInfo, String> dayGradeWeiTC = new TableColumn<>("平时成绩权重");
        TableColumn<StudentGradeInfo, String> courseGradeTC = new TableColumn<>("课程考试成绩");
        TableColumn<StudentGradeInfo, String> sumGradeTC = new TableColumn<>("总成绩");
        TableColumn<StudentGradeInfo, String> exemptTC = new TableColumn<>("是否免代修");
        TableColumn<StudentGradeInfo, Integer> creditHourTC = new TableColumn<>("获得学分");
        TableColumn<StudentGradeInfo, String> stateTC = new TableColumn<>("课程结业状态");
        TableColumn<StudentGradeInfo, HBox> operateTC = new TableColumn<>("操作");

        //2.2 列头添加到视图
        tableView.getColumns().addAll(selectTC, nameTC, numberTC, genderTC, dayGradeTC, dayGradeWeiTC, courseGradeTC, sumGradeTC,
                exemptTC, creditHourTC, stateTC, operateTC);

        //3.模拟数据
        //3.1 新建多个假数据
        List<StudentGradeInfo> studentGradeInfos = simulatedData();
        //3.2 格式转化(用户数据集合转换成Javafx组件集合)
        ObservableList<StudentGradeInfo> users = FXCollections.observableArrayList(studentGradeInfos);
        //3.3 数据添加到表格
        tableView.setItems(users);

        //4.映射（让每一列知道要展示的属性是哪一个）
        selectTC.setCellValueFactory(new PropertyValueFactory<>("select"));
        nameTC.setCellValueFactory(new PropertyValueFactory<>("name"));
        numberTC.setCellValueFactory(new PropertyValueFactory<>("number"));
        genderTC.setCellValueFactory(new PropertyValueFactory<>("gender"));
        dayGradeTC.setCellValueFactory(new PropertyValueFactory<>("dayGrade"));
        dayGradeWeiTC.setCellValueFactory(new PropertyValueFactory<>("dayGradeWei"));
        courseGradeTC.setCellValueFactory(new PropertyValueFactory<>("courseGrade"));
        sumGradeTC.setCellValueFactory(new PropertyValueFactory<>("sumGrade"));
        exemptTC.setCellValueFactory(new PropertyValueFactory<>("exempt"));
        creditHourTC.setCellValueFactory(new PropertyValueFactory<>("creditHour"));
        stateTC.setCellValueFactory(new PropertyValueFactory<>("status"));
        operateTC.setCellValueFactory(new PropertyValueFactory<>("operate"));

        //试图添加
        ObservableList<Node> tableChildren = listVBox.getChildren();
        tableChildren.add(tableView);

    }

    /**
     * 列表区域的操作按钮初始化
     *
     * @param listVBox 列表盒子
     */
    private void operateBtnInit(MyVBox listVBox) {

        //操作区域
        MyHBox myHBox = new MyHBox();
        listVBox.getChildren().add(myHBox);

        //布局
        Insets insets = new Insets(10);
        myHBox.setPadding(insets);
        myHBox.setSpacing(15);


        //组件(操作按钮)
        Button passBtn = new Button("课程结业通过");
        myHBox.getChildren().add(passBtn);

        Button notPassBtn = new Button("课程结业不通过");
        myHBox.getChildren().add(notPassBtn);

        Button toLeadBtn = new Button("批量导入课程考试成绩");
        myHBox.getChildren().add(toLeadBtn);

        Button calculateSumBtn = new Button("计算总成绩");
        myHBox.getChildren().add(calculateSumBtn);

        Button synchronizationBtn = new Button("同步到学籍信息并发布成绩及结业信息");
        myHBox.getChildren().add(synchronizationBtn);


    }

    /**
     * 列表界面模拟数据
     *
     * @return 模拟好的数据集合
     */
    private List<StudentGradeInfo> simulatedData() {

        //数据总集合
        List<StudentGradeInfo> studentGradeInfos = new ArrayList<>();

        //模拟第一条数据
        oneSimulateData(studentGradeInfos);

        //模拟第二条数据
        twoSimulateData(studentGradeInfos);

        //模拟第三条数据
        threeSimulateData(studentGradeInfos);

        //模拟第四条数据
        fourSimulateData(studentGradeInfos);


        //返回全部数据
        return studentGradeInfos;
    }

    /**
     * 第四条数据模拟
     *
     * @param studentGradeInfos 总数据集合
     */
    private void fourSimulateData(List<StudentGradeInfo> studentGradeInfos) {

        //第四条
        //通用按钮盒子
        HBox generalHBox = generalHBoxInit();
        //界面数据对象
        StudentGradeInfo studentGradeInfo = new StudentGradeInfo();
        studentGradeInfo.setSelect(generalHBox);
        studentGradeInfo.setName("田吉");
        studentGradeInfo.setDayGrade("90");
        studentGradeInfo.setDayGradeWei("40%");
        studentGradeInfo.setCourseGrade("80");
        studentGradeInfo.setSumGrade("84");
        studentGradeInfo.setCreditHour(4);
        studentGradeInfo.setState("通过");

        studentGradeInfos.add(studentGradeInfo);
    }


    /**
     * 第三条数据模拟
     *
     * @param studentGradeInfos 总数据集合
     */
    private void threeSimulateData(List<StudentGradeInfo> studentGradeInfos) {

        //第三条
        //通用按钮盒子
        HBox generalHBox = generalHBoxInit();
        //界面数据对象
        StudentGradeInfo studentGradeInfo = new StudentGradeInfo();
        studentGradeInfo.setSelect(generalHBox);
        studentGradeInfo.setName("钟楼");
        studentGradeInfo.setDayGrade("70");
        studentGradeInfo.setDayGradeWei("40%");
        studentGradeInfo.setCourseGrade("50");
        studentGradeInfo.setSumGrade("58");
        studentGradeInfo.setState("不通过");

        studentGradeInfos.add(studentGradeInfo);
    }

    /**
     * 第二条数据模拟
     *
     * @param studentGradeInfos 总数据集合
     */
    private void twoSimulateData(List<StudentGradeInfo> studentGradeInfos) {

        //第二条
        //通用按钮盒子
        HBox generalHBox = generalHBoxInit();
        //界面数据对象
        StudentGradeInfo studentGradeInfo = new StudentGradeInfo();
        studentGradeInfo.setSelect(generalHBox);
        studentGradeInfo.setName("董晓晓");
        studentGradeInfo.setNumber("002");
        studentGradeInfo.setGender("女");
        studentGradeInfo.setDayGrade("-");
        studentGradeInfo.setDayGradeWei("40%");
        studentGradeInfo.setCourseGrade("-");
        studentGradeInfo.setSumGrade("合格");
        studentGradeInfo.setExempt("是");
        studentGradeInfo.setCreditHour(4);
        studentGradeInfo.setState("通过");

        studentGradeInfos.add(studentGradeInfo);
    }

    /**
     * 第一条数据模拟
     *
     * @param studentGradeInfos 总数据集合
     */
    private void oneSimulateData(List<StudentGradeInfo> studentGradeInfos) {

        //第一条
        //操作按钮盒子
        HBox operateHBox = operateHBoxInit();
        //通用按钮盒子
        HBox generalHBox = generalHBoxInit();
        //界面数据对象
        StudentGradeInfo studentGradeInfo = new StudentGradeInfo();
        studentGradeInfo.setSelect(generalHBox);
        studentGradeInfo.setName("陆小七");
        studentGradeInfo.setNumber("001");
        studentGradeInfo.setGender("男");
        studentGradeInfo.setDayGrade("80");
        studentGradeInfo.setDayGradeWei("40%");
        studentGradeInfo.setCourseGrade("70");
        studentGradeInfo.setSumGrade("74");
        studentGradeInfo.setState("未设置");
        studentGradeInfo.setOperate(operateHBox);

        studentGradeInfos.add(studentGradeInfo);
    }

    /**
     * 通用盒子初始化
     *
     * @return 通用盒子
     */
    private HBox generalHBoxInit() {

        //新建操作盒子
        HBox operateHBox = new HBox();
        operateHBox.setPadding(new Insets(2));
        operateHBox.setSpacing(10);

        //操作按钮
        CheckBox checkBox = new CheckBox();
        operateHBox.getChildren().add(checkBox);

        return operateHBox;
    }

    /**
     * 操作按钮盒子初始化
     *
     * @return 操作按钮盒子
     */
    private HBox operateHBoxInit() {

        //新建操作盒子
        HBox operateHBox = new HBox();
        operateHBox.setPadding(new Insets(2));
        operateHBox.setSpacing(10);

        //操作标签
        Label passLab = new Label("通过");
        operateHBox.getChildren().add(passLab);

        Label notPassLab = new Label("不通过");
        operateHBox.getChildren().add(notPassLab);

        return operateHBox;
    }

    /**
     * 按钮横向盒子
     *
     * @param buttonHBox 按钮盒子
     */
    private void initButtonHBox(HBox buttonHBox) {

        buttonHBox.setSpacing(20);
        buttonHBox.setPadding(new Insets(5));
        //查看学员按钮
        Button lookStuBtn = new Button("查看学员");
        LookStuBtnAction lookStuBtnAction = new LookStuBtnAction();
        lookStuBtn.setOnAction(lookStuBtnAction);

        //查看课程资源按钮
        Button lookCourseResourceBtn = new Button("查看课程资源");
        ObservableList<Node> children = buttonHBox.getChildren();
        children.addAll(lookStuBtn, lookCourseResourceBtn);
        //查看课程资源按钮事件
        PageTeachingSuperviseLookCourseResourceBtnAction pageTeachingSuperviseLookCourseResourceBtnAction = new PageTeachingSuperviseLookCourseResourceBtnAction();
        lookCourseResourceBtn.setOnAction(pageTeachingSuperviseLookCourseResourceBtnAction);

        //教师值机按钮
        Button teachingCheckBtn = new Button("教师值机管理");
        ObservableList<Node> teachingCheckBtnChildren = buttonHBox.getChildren();
        teachingCheckBtnChildren.add(teachingCheckBtn);
        //事件
        TeachingCheckBtn teachingCheckBtnAction = new TeachingCheckBtn();
        teachingCheckBtn.setOnAction(teachingCheckBtnAction);

        //实时课堂按钮
        Button realTimeClassBtn = new Button("实时课堂管理");
        ObservableList<Node> realTimeClassBtnChildren = buttonHBox.getChildren();
        realTimeClassBtnChildren.add(realTimeClassBtn);
        RealTimeClassBtn realTimeClassBtnAction = new RealTimeClassBtn();
        realTimeClassBtn.setOnAction(realTimeClassBtnAction);

        //成绩及结业按钮
        Button gradeBtn = new Button("成绩及结业管理");
        ObservableList<Node> gradeBtnChildren = buttonHBox.getChildren();
        gradeBtnChildren.add(gradeBtn);
        GradeBtn gradeBtnBtnAction = new GradeBtn();
        gradeBtn.setOnAction(gradeBtnBtnAction);

    }


    /**
     * 定位区域初始化
     *
     * @param locationHBox 定位区域容器
     */
    private void locationHBoxInit(MyHBox locationHBox) {

        //控制数据
        int height = 42;

        //大小
        locationHBox.setPrefHeight(height);

        //布局
        Insets insets = new Insets(5);
        locationHBox.setPadding(insets);
        locationHBox.setSpacing(0);
        locationHBox.setAlignment(Pos.CENTER_LEFT);

        //组件
        Label siteLab = new Label("当前位置：");
        Label oneCatalogLab = new Label("🏠>教学管理");
        Label twoCatalogLab = new Label(">教学监督");
        Label threeCatalogLab = new Label(">实时中的教学安排");
        Label fourCatalogLab = new Label(">成绩及结业管理");

        //添加组件
        locationHBox.getChildren().addAll(siteLab, oneCatalogLab, twoCatalogLab,threeCatalogLab,fourCatalogLab);

    }
}
